package com.cjh.service.impl;

import com.cjh.dao.UserMapper;
import com.cjh.entity.User;
import com.cjh.service.IUserService;
import com.cjh.util.PageUtilConfig;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserMapper userMapper;

    public PageInfo<User> selectListByPage(int pageNum) {
        Page<User> objects = PageHelper.startPage(pageNum, PageUtilConfig.USER_PAGE_ZIZE);
        return new PageInfo<>(userMapper.selectAll());
    }

    public int deleteByPrimaryKey(Integer id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    public User insert(User record) {
        if(userMapper.insert(record) > 0){
            return userMapper.selectByPrimaryKey(record.getId());
        }else return null;
    }

    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }
}
